import Vue from 'vue';
import Router from 'vue-router';
import Layout from '@/layout';

Vue.use(Router);

/**
 * title: 侧边栏显示名称   icon: 图标
 */
export const routes = [
    {
        path: '/login',
        component: () => import('@/views/login/Login'),
        hidden: true
    },
    {
        path: '/404',
        component: () => import('@/views/404'),
        hidden: true
    },
    {
        path: '/',
        redirect: '/manager/list',
    },
    {
        name: 'manager',
        path: '/manager',
        component: Layout,
        redirect: "list",
        meta: {title: '管理员模块', icon: 'el-icon-s-custom'},
        children: [
            {
                name: 'managerList',
                path: 'list',
                component: () => import('@/views/manager/ManagerList'),
                meta: {title: '管理员列表', icon: 'el-icon-tickets'}
            },
            {
                name: 'managerAdd',
                path: 'add',
                component: () => import('@/views/manager/ManagerAdd'),
                meta: {title: '添加管理员', icon: 'el-icon-edit-outline'}
            }
        ]
    },
    {
        name: 'user',
        path: '/user',
        component: Layout,
        redirect: 'list',
        meta: {title: '会员管理', icon: 'el-icon-user-solid'},
        children: [
            {
                name: 'userList',
                path: 'list',
                component: () => import('@/views/user/UserList'),
                meta: {title: '会员列表', icon: 'el-icon-user-solid'}
            }
        ]
    },
    {
        name: 'combo',
        path: '/combo',
        component: Layout,
        redirect: "list",
        meta: {title: '套餐管理', icon: 'el-icon-s-goods'},
        children: [
            {
                name: 'comboList',
                path: 'list',
                component: () => import('@/views/combo/ComboList'),
                meta: {title: '套餐列表', icon: 'el-icon-tickets'}
            },
            {
                name: 'comboAdd',
                path: 'add',
                component: () => import('@/views/combo/ComboAdd'),
                meta: {title: '添加套餐', icon: 'el-icon-edit-outline'}
            }
        ]
    },
    {
        name: 'banner',
        path: '/banner',
        component: Layout,
        redirect: "list",
        meta: {title: '轮播管理', icon: 'el-icon-picture'},
        children: [
            {
                name: 'bannerList',
                path: 'list',
                component: () => import('@/views/banner/BannerList'),
                meta: {title: '轮播列表', icon: 'el-icon-tickets'}
            },
            {
                name: 'bannerAdd',
                path: 'add',
                component: () => import('@/views/banner/BannerAdd'),
                meta: {title: '添加轮播 ', icon: 'el-icon-edit-outline'}
            }
        ]
    },
    {
        name: 'menu',
        path: '/menu',
        component: Layout,
        redirect: 'list',
        meta: {title: '菜谱管理', icon: 'el-icon-s-order'},
        children: [
            {
                name: 'menuList',
                path: 'list',
                component: () => import('@/views/menu/MenuList'),
                meta: {title: '菜谱列表', icon: 'el-icon-s-order'}
            }
        ]
    },
    // 其余未匹配路径跳转404
    {
        path: '*', 
        redirect: '/404', 
        hidden: true
    }
];

const createRouter = () => {
    return new Router({
        mode: 'history',
        scrollBehavior: () => ({y: 0}),
        routes
    });
};

const router = createRouter();

export default router;
